package com.plus1024.ai.springaidemo.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AiController {

    final ChatClient chatClient;

    @Autowired
    public AiController(ChatClient chatClient) {
        this.chatClient = chatClient;
    }
    
    @GetMapping("/ai/chat")
    public String chat(@RequestParam(value = "message", defaultValue = "hello") String message) {
        return chatClient.prompt().user(message).call().content();
    }
}